<?php

namespace app\admin\controller;

use app\common\BaseController;
use app\model\SysUser;
use think\Request;
use think\Session;
use think\Url;

class Login extends BaseController {
	/**
	 * 用户登录
	 */
	public function index() {
		if ($this->request->isPost ()) {
			$account = $this->request->param ( "account" );
			$password = $this->request->param ( "password" );
			$reslut = SysUser::findByAccount ( $account );
			if ($reslut && $reslut->verify ( $password )) {
				Session::set ( 'certificates.account', $account );
				Session::set ( 'certificates.isAuthc', true );
				$this->redirect ( Session::get ( "certificates.url" ) ?: "/admin" );
			} else {
				$this->assign ( "account", $account );
				$this->assign ( "password", $password );
				$this->assign ( "msg", "账号或者密码错误" );
				return $this->fetch ();
			}
		} else {
			return $this->fetch ();
		}
	}
	/**
	 * 退出登录
	 */
	public function logout() {
		Session::clear ();
		return $this->success ( "退出成功！", '/admin/login' );
	}
}
